<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="skripte/Cookies.js"></script>
<script src="skripte/proba1.js"></script>
<script src="skripte/redirect.js"></script>
<script src="jQuery/jquery-1.10.2.js"></script>
<LINK href="stilovi/login.css" rel="stylesheet" type="text/css">
<LINK href="stilovi/coda-slider.css" rel="stylesheet" type="text/css">
<LINK href="stilovi/templatemo_style.css" rel="stylesheet" type="text/css">
<LINK href="stilovi/registracija.css" rel="stylesheet" type="text/css">
<link rel="icon" type="image/gif" href="slike/animated_favicon1.gif">
<title>Prijava</title>
</head>
<body>
<div id="slider">

	<div id="templatemo_main">
    	<ul id="social_box">
            <h1> Javna saobraćajna mreža Bosne i Hercegovine </h1>         
        </ul>
        
        <div id="content">
     
            <div class="scroll">
                <div class="scrollContainer">
                
                    <div class="panel" id="home">
                        
							<div id="naslov">
								<h1> Prijava na sistem:</h1>
							</div>
							
								<div id="logDiv">
								<form id="loginForm">
								<div id="unos">
								<table border=0>
								<tr><td>Korisnik:</td><td><input type="text" id="uname"></td></tr>
								<tr><td>Šifra:</td><td><input type="password" id="pass"></td></tr>
								</table>
								</div>
								<button type="button" onClick="reaguj()" class="btn">Log in</button>
								<input type="button" class="btn" value="Nazad" onclick="location.href='index.html#login';">
								</form>
							</div>
							
							<div id="logOut">
								<h4>Logovani ste, ako se želite odjaviti pritisnite sljedeće dugme: </h4>
								<button type="button" onClick="outReaguj()" class="btn">Odjavi me</button>
							</div>
						
							
							
							
							<script>
							if(readCookie('login')!=null&&readCookie('login')!='gost') {
								$('#logDiv').hide();
								$('#regDiv').hide();
								$('#logOut').show();
							}
							else
								{
								$('#logDiv').show();
								$('#logOut').hide();
								}
							function reaguj()
							{
								
								var uname=$('#uname').val();
								if(uname.length<1){
									alert('Niste unijeli vaše korisničko ime!');
									return;
								}
								var req = createRequest(); // defined above
								// Create the callback:
								req.onreadystatechange = function() {
								  if (req.readyState != 4) return; // Not there yet
								  if (req.status != 200) {
								    // Handle request failure here...
								    return;
								  }
								  // Request successful, read the response
								  var resp = req.responseText;
								  // ... and use it as needed by your app.
								  if(resp=="true"){
									  	createCookie('login',uname,1);
										usmjeri(uname);
								  }
								  else{
									  alert("Pogrešno korisničko ime ili password!");
								  }
								  return;
								}
								req.open("POST","korisno/login/provjera", true);
								var parametar="user="+$('#uname').val()+"&pass="+$('#pass').val();
								req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
								req.setRequestHeader("Content-length", parametar.length);
								//req.setRequestHeader("Connection", "close");
								req.send(parametar);
							}
							function gost()
							{
								createCookie('login','gost',1);
								usmjeri('gost');
							}
							function outReaguj()
							{
								if(readCookie('login')!=null)
								{
									eraseCookie('login');
									invalidateSession();								
								}	
								 
							}
							function testiraj()
							{
								var req = createRequest(); // defined above
								// Create the callback:
								req.onreadystatechange = function() {
								  if (req.readyState != 4) return; // Not there yet
								  if (req.status != 200) {
								    // Handle request failure here...
								    return;
								  }
								  // Request successful, read the response
								  var resp = req.responseText;
								  // ... and use it as needed by your app.
								  alert(resp);
								  return;
								}
								req.open("GET","korisno/users/test", true);
								req.send();
							}
							function invalidateSession()
							{
								var req = createRequest(); // defined above
								// Create the callback:
								req.onreadystatechange = function() {
								  if (req.readyState != 4) return; // Not there yet
								  if (req.status != 200) {
								    // Handle request failure here...
								    return;
								  }
								  // Request successful, read the response
								  var resp = req.responseText;
								  // ... and use it as needed by your app.
								  alert('Sada ste se odjavili!');
								  location.reload();
								  return;
								}
								req.open("GET","korisno/login/obrisisession", true);
								req.send();
							}
							</script>

                      <div class="cleaner_h40"></div>
                    </div> 
				</div>
			</div>
		</div>
	</div>
</div>

</body>
</html>